/*
 * 
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding GB2312
 */
package net.comm.group.service.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Vector;

import net.comm.check.service.impl.JifenServiceImpl;
import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;
import net.comm.oper.service.impl.OperLogServiceImpl;
import net.comm.oper.web.form.OperLogForm;
import net.comm.param.service.impl.SequenceMgr;
import net.comm.common.common;
import net.comm.file.service.impl.FilesServiceImpl;
import net.comm.file.web.form.FilesForm;
import net.comm.group.bean.BaseGparty;
import net.comm.group.db.DbGpartyService;
import net.comm.group.db.GpartyServiceSqlMysql;
import net.comm.group.web.form.GdianpingForm;
import net.comm.group.web.form.GpartyForm;
import net.comm.group.web.form.GsignupForm;


import net.comm.page.PageCtr;

import net.comm.tags.JstlFun;
import net.comm.user.service.impl.UserSysinfoServiceImpl;
import net.comm.user.web.form.UserSysinfoForm;
import net.comm.util.DatetimeUtil;
import net.comm.util.DbcpPool;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.sakaiproject.db.impl.BasicSqlService;


/**
 *
 * @author hcgong(gong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class GpartyServiceImpl {

	static Logger logger = Logger.getLogger(GpartyServiceImpl.class.getName());

	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List list(GpartyForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getCountSql1();

			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(bSqlServ.dbCount(cn, sql, null));
			page.caculate();

			//取得FORM中传入的查询参数
			Object[] fields2 = new Object[2];
			
			fields2[1] = page.getPos()-1;
			fields2[2] = page.getPageSize();
			
			sql = servSql.getRecbyPageSql();

			
			list = bSqlServ.dbRead(cn, sql, fields2, new DbGpartyService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}
	/**
	 * 我加入的活动
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List listMyAdd(GpartyForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			Object[] fields = new Object[2];
			
			fields[0] = theForm.getQryGroupID();
			fields[1] = theForm.getQryUserID();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getCountSql2();

			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(bSqlServ.dbCount(cn, sql, fields));
			page.caculate();

			//取得FORM中传入的查询参数
			Object[] fields2 = new Object[4];
			
			fields2[0] = theForm.getQryGroupID();
			fields2[1] = theForm.getQryUserID();
			fields2[2] = page.getPos()-1;
			fields2[3] = page.getPageSize();
			
			sql = servSql.getRecMyaddSql();
			
			list = bSqlServ.dbRead(cn, sql, fields2, new DbGpartyService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}
	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List adlist(GpartyForm theForm,  ReturnMessage msg) 
	{
		List list = new Vector();

		Connection cn = null;
		Statement stmt=null;
		ResultSet rs=null;
		try
		{
			cn = DbcpPool.getConnection();
			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			
			StringBuffer sb = new StringBuffer(" where 1=1");

			if(theForm.getQryFirsort() > 0 ){
				
				sb.append(" and Firsort = ");
				sb.append(theForm.getQryFirsort());
				sb.append(" ");
			}
			if(theForm.getQryGroupID() > 0 ){
				
				sb.append(" and GroupID = ");
				sb.append(theForm.getQryGroupID());
				sb.append(" ");
			}
			
			if(theForm.getQryUserID() > 0 ){
				
				sb.append(" and UserID = ");
				sb.append(theForm.getQryUserID());
				sb.append(" ");
			}

			String qryTitle = theForm.getQryTitle().replaceAll(GlbFinal.SQLINjection, " ");			
			if(!qryTitle.equals("")){
				
				sb.append(" and title like '%");
				sb.append(qryTitle);
				sb.append("%'");
			}
			
			if(!theForm.getQryStatus().equals("")){
				
				sb.append(" and status ='");
				sb.append(theForm.getQryStatus());
				sb.append("'");
			}else{
				sb.append(" and status = '");
				sb.append(GlbFinal.STS_NORMAL);
				sb.append("'");
			}
			String orderby = theForm.getQryOrderby().replaceAll(GlbFinal.SQLINjection, " ");
			if(!orderby.equals("")){
				sb.append(" Order by ");
				sb.append(orderby);
				sb.append(" ");
				
			}else{
				sb.append(" Order by Mtime desc ");
			}

			//查询记录数
			stmt = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			String sql = servSql.getCountSql1();

			logger.debug(sql+sb.toString());
			rs=stmt.executeQuery(sql+sb.toString());
			int nRows = 0;
			if (rs.next())
	           nRows = rs.getInt("COUNT");
			else
			{
	            rs.close();
	            stmt.close();
	            DbcpPool.returnConnection(cn);
			    return list;
			}
			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(nRows);
			page.caculate();

			sb.append(" limit ");
			sb.append(page.getPos()-1);
			sb.append(", ");
			sb.append(page.getPageSize());
			
			 //取记录
			 sql = servSql.getRecSql();
			 logger.debug(sql+sb.toString());
			 DbGpartyService dbservice = new DbGpartyService();
			 
			 rs=stmt.executeQuery(sql+sb.toString());
			 while (rs.next())
			 {
				try
				{
					Object obj = dbservice.readSqlResultRecord(rs);
					if (obj != null) list.add(obj);
				}
				catch (Throwable t)
				{
					logger.error(t.getMessage());
				}		
			 }
			 rs.close();
			 stmt.close();
		     DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				DbcpPool.returnConnection(cn);
			} catch (Exception ex1) {
				ex1.printStackTrace();
			}			
	    }finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}			
			DbcpPool.returnConnection(cn);
		}		
		return list;
	}
	
	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(GpartyForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			DbcpPool.beginTran(cn);
			
			get(cn, theForm, msg);
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about musicalbum" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(Connection cn, GpartyForm theForm, ReturnMessage msg) 
	{
		try
		{
			
			List list = null;

			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getPartyID();			
			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbGpartyService());
			
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseGparty base = (BaseGparty)list.get(0);
				
			BeanUtils.copyProperties(theForm, base);
			
			//更新点击次数
			Object[] fields1 = new Object[6];
			
			fields1[0] = theForm.getSignNum();			
			fields1[1] = theForm.getAttach() + 1;			
			fields1[2] = theForm.getUpCnt();			
			fields1[3] = theForm.getDownCnt();			
			fields1[4] = theForm.getStatus();			
			fields1[5] = theForm.getPartyID();			

			sql = servSql.getUpdnumSql();
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields1);
			if(!res){
				common.setAppFailMsg(msg , " 登记活动失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;
			}	
			
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about musicalbum" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
		
		return ;
	}	
	/**
	 * 添加活动到表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add(GpartyForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			//检查活动发起时间 结束日期 截止日期
			
			String  bgtime = DatetimeUtil.DeFormatDate14(theForm.getBgtime());
			String endtime = DatetimeUtil.DeFormatDate14(theForm.getEndtime());
			String signEtime = DatetimeUtil.DeFormatDate14(theForm.getSignEtime());
			String currtime = DatetimeUtil.getDatetime();
			
			if(DatetimeUtil.getQuot(bgtime, currtime) < 1){
				common.setAppFailMsg(msg , " 活动开始时间需在24小时以后！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;					
			}
			if(!endtime.equals("") && DatetimeUtil.getQuot(endtime, signEtime) < 0){
				common.setAppFailMsg(msg , " 报名截止时间不能小于活动结束时间！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;					
			}
			if(!endtime.equals("") && DatetimeUtil.bjudgeRange(bgtime, endtime)){
				common.setAppFailMsg(msg , " 报名结束时间应大于活动开始时间！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;					
			}
			

			//取活动发起者积分
			UserSysinfoServiceImpl syservice = new UserSysinfoServiceImpl();
			UserSysinfoForm sysform = new UserSysinfoForm();
			
			//更新被验证会员积分
			sysform.setUserID(theForm.getUserID());
			
			syservice.get(cn, sysform, msg);
			if(msg.getErrCode() != 0){
				return;
			}		
			if(sysform.getIntegral() < 500){
				common.setAppFailMsg(msg , " 您的积分低于500，不允许发起活动！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;				
			}
			
			//更新活动发起者积分
			JifenServiceImpl jifenservice = new JifenServiceImpl();
			
			jifenservice.compjf(cn, 17, theForm.getUserID(), msg);
			if(msg.getErrCode() != 0){
				return;
			}				
			
			
			theForm.setPartyID(SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE, GlbFinal.SEQ_GPARTYID));
			
			//上传活动海报
			if(theForm.getFilepath() != null&&!theForm.getFilepath().getFileName().equals("")){
				
				FilesForm fileForm = new FilesForm();
				fileForm.setFormFile(theForm.getFilepath());
				fileForm.setF_info(theForm.getTitle());
				fileForm.setF_Zip(GlbFinal.ZIP_600);
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				
				fileservice.add(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}
				theForm.setSmallPic(fileForm.getF_ID());
			}	
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[26];
			
			fields[0] = theForm.getPartyID();			//	活动序号
			fields[1] = theForm.getGroupID();			//	群组ID
			fields[2] = theForm.getTitle();				//	活动主题
			fields[3] = theForm.getInfo();				//	介绍
			fields[4] = theForm.getSmallPic();			//	活动首页小海报ID
			fields[5] = DatetimeUtil.DeFormatDate14(theForm.getBgtime());			//	活动起始日期时间
			fields[6] = DatetimeUtil.DeFormatDate14(theForm.getEndtime());			//	活动结束日期时间
			fields[7] = theForm.getWork_location();			//	活动省份
			fields[8] = theForm.getWork_sublocation();	//	活动城市
			fields[9] = theForm.getFirsort();			//	活动省份
			fields[10] = theForm.getSecsort();				//	活动城市
			fields[11] = theForm.getThisort();			//	活动省份
			fields[12] = theForm.getPlace();			//	地点
			fields[13] = theForm.getTel();				//	联系方式
			fields[14] = DatetimeUtil.DeFormatDate14(theForm.getSignEtime());		//	报名截止时间
			fields[15] = theForm.getCharge();			//	活动费用
			fields[16] = theForm.getPlanNum();			//	计划活动人数
			fields[17] = theForm.getSignNum();			//	目前报名人数
			fields[18] = theForm.getOrganType();		//	组织人类型
			fields[19] = theForm.getUserID();			//	组织人ID
			fields[20] = DatetimeUtil.getDatetime();	//	发起日期
			fields[21] = theForm.getAttach();			//	点击数
			fields[22] = theForm.getUpCnt();			//	
			fields[23] = theForm.getDownCnt();			//	
			fields[24] = theForm.getStatus();			//	状态
			fields[25] = DatetimeUtil.getDatetime();	//	最后修改日期时间			
			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getInsertSql();
						
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 添加活动失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;
			}
			//添加报名人数
			GsignupServiceImpl signservice = new GsignupServiceImpl();
			GsignupForm signForm = new GsignupForm();
			
			signForm.setUserID(theForm.getUserID());
			signForm.setPartyID(theForm.getPartyID());
			
			signservice.onlyadd(cn, signForm, msg);
			if(msg.getErrCode() != 0){
				
				return;
			}

			//添加用户动态表
			OperLogServiceImpl logservice = new OperLogServiceImpl();
			OperLogForm logForm = new OperLogForm();
			
			logForm.setUserID(theForm.getUserID());
			logForm.setType(GlbFinal.OPERTYPE_HUODONG);						//群活动
			
			String[] arr = new String[7];
			arr[0] = JstlFun.GetUserNick(theForm.getUserID());			//主操作者		
			arr[1] = "";												//主动者与被动者的关系副词
			arr[2] = "";												//被动接受者ID
			arr[3] = "";												//被动接受者姓名
			arr[4] = "发起了新活动：";									//操作
			arr[5] = theForm.getTitle();								//操作对象名称
			arr[6] = String.valueOf(theForm.getPartyID());				//操作对象KEY，多个字段以'|'分隔

			logForm.setLogarr(arr);
			
			logservice.add(cn, logForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}				
			//
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about musicalbum" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}

	/**
	 * 删除一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(GpartyForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			
			List list = null;

			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getPartyID();			
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbGpartyService());
			
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			BaseGparty base = (BaseGparty)list.get(0);			
			BeanUtils.copyProperties(theForm, base);
			
			if(base.getSmallPic() > 0){
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				FilesForm fileForm = new FilesForm();
				
				fileForm.setF_ID(base.getSmallPic());
				fileservice.delete(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}
			}
			
			sql = servSql.getDeleteSql();
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 删除记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			//删除所有报名记录
			GsignupServiceImpl signupservice = new GsignupServiceImpl();
			GsignupForm signupForm = new GsignupForm();
			
			signupForm.setPartyID(theForm.getPartyID());
			
			signupservice.delall(cn, signupForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			//删除所有点评记录
			GdianpingServiceImpl dpservice = new GdianpingServiceImpl();
			GdianpingForm dpform = new GdianpingForm();
			
			dpform.setDsort(GlbFinal.DSORT_PARTY);
			dpform.setDsortID(theForm.getPartyID());
			
			dpservice.delbydsortID(cn, dpform, msg);
			if(msg.getErrCode() != 0){
				return;
			}			
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about musicalbum" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}

	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void update(GpartyForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			DbcpPool.beginTran(cn);
			

			//上传活动海报
			if(theForm.getFilepath() != null&&!theForm.getFilepath().getFileName().equals("")){
				
				FilesForm fileForm = new FilesForm();
				fileForm.setFormFile(theForm.getFilepath());
				fileForm.setF_info(theForm.getTitle());
				fileForm.setF_Zip(GlbFinal.ZIP_600);
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				
				fileservice.add(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}
				theForm.setSmallPic(fileForm.getF_ID());
			}			

			//取得FORM中传入的查询参数
			Object[] fields = new Object[26];
			
			fields[0] = theForm.getGroupID();			//	群组ID
			fields[1] = theForm.getTitle();				//	活动主题
			fields[2] = theForm.getInfo();			//	介绍
			fields[3] = theForm.getSmallPic();			//	活动首页小海报ID
			fields[4] = DatetimeUtil.DeFormatDate14(theForm.getBgtime());			//	活动起始日期时间
			fields[5] = DatetimeUtil.DeFormatDate14(theForm.getEndtime());			//	活动结束日期时间
			fields[6] = theForm.getWork_location();			//	活动省份
			fields[7] = theForm.getWork_sublocation();				//	活动城市
			fields[8] = theForm.getFirsort();			//	活动省份
			fields[9] = theForm.getSecsort();				//	活动城市
			fields[10] = theForm.getThisort();			//	活动省份
			fields[11] = theForm.getPlace();			//	地点
			fields[12] = theForm.getTel();			//	联系方式
			fields[13] = DatetimeUtil.DeFormatDate14(theForm.getSignEtime());		//	报名截止时间
			fields[14] = theForm.getCharge();				//	活动费用
			fields[15] = theForm.getPlanNum();			//	计划活动人数
			fields[16] = theForm.getSignNum();			//	目前报名人数
			fields[17] = theForm.getOrganType();		//	组织人类型
			fields[18] = theForm.getUserID();				//	组织人ID
			fields[19] = DatetimeUtil.getDatetime();			//	发起日期
			fields[20] = theForm.getAttach();				//	点击数
			fields[21] = theForm.getUpCnt();			//	
			fields[22] = theForm.getDownCnt();			//	
			fields[23] = theForm.getStatus();			//	状态
			fields[24] = DatetimeUtil.getDatetime();			//	最后修改日期时间		
			fields[25] = theForm.getPartyID();			//	活动序号

			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getUpdateSql();
						
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 登记活动失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;
			}
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about musicalbum" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * 更新一条指定记录状态
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updsts(GpartyForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			DbcpPool.beginTran(cn);
			
			updsts( cn, theForm,  msg);
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about musicalbum" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * 更新一条指定记录状态
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updsts(Connection cn, GpartyForm theForm, ReturnMessage msg) 
	{
		
		try
		{
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getPartyID();			
			
			GpartyServiceSqlMysql servSql = new GpartyServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getbykeySql();			
					
			List list = bSqlServ.dbRead(cn, sql, fields, new DbGpartyService());
			
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseGparty base = (BaseGparty)list.get(0);	
			
			if(theForm.getStatus().equals("")){
				theForm.setStatus(base.getStatus());
			}
			
			//取得FORM中传入的查询参数
			Object[] fields2 = new Object[6];
			
			fields2[0] = base.getSignNum() + theForm.getSignNum();
			fields2[1] = base.getAttach() + theForm.getAttach();
			fields2[2] = base.getUpCnt() + theForm.getUpCnt();
			fields2[3] = base.getDownCnt() + theForm.getDownCnt();
			fields2[4] = theForm.getStatus();
			fields2[5] = theForm.getPartyID();
			
			sql = servSql.getUpdnumSql();
						
			boolean  res = bSqlServ.dbWrite(cn, sql, fields2);
			if(!res){
				common.setAppFailMsg(msg , " 更新活动失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;
			}

		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about musicalbum" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
		
		return ;
	}	
}
